import re
import os
import my_function as my
# holy sites
with open(r'ck3/game_path.txt', 'r', encoding='utf-8') as file:
    game_path = file.read()  # 读取全部内容到一个字符串

file_path = game_path + "/game/common/religion/holy_sites/00_holy_sites.txt"
regular_pattern = r'county = .*'
new_pattern = 'county = c_wanan'
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()

content = re.sub(regular_pattern, new_pattern, content)

regular_pattern = r'barony = .*'
new_pattern = 'barony = b_wanan_1'
content = re.sub(regular_pattern, new_pattern, content)

with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# pilgrim
file_path = game_path + "/game/common/activities/activity_types/pilgrimage.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = 'b_makka'
new_pattern = 'b_wanan_1'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# invite courts
# file_path = game_path + "/game/common/activities/activity_types/pilgrimage.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = 'gold >= .*'
# new_pattern = 'gold >= 0'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# contract
file_path = game_path + "/game/common/character_interactions/00_modifiy_vassal_contract.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = 'subject_contract_is_blocked_from_modification'
new_pattern = '#subject_contract_is_blocked_from_modification'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# era
# file_path = game_path + "/game/common/culture/eras/00_culture_eras.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'year = .*'
# new_pattern = r'year = 9999'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# block_head = "culture_era_tribal"
# file_path = game_path + "/game/common/culture/eras/00_culture_eras.txt"
# new_block_content = block_head + """ = {
#     year = 0
# }"""
# my.replace_block(file_path, block_head, new_block_content)

## ai
# file_path = game_path + "/game/common/defines/ai/00_ai.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'AI_BASE_WAR_CHANCE = .*'
# new_pattern = r'AI_BASE_WAR_CHANCE = 100'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'RETREAT_COMBAT_PREDICTION_RATIO = .*'
# new_pattern = r'RETREAT_COMBAT_PREDICTION_RATIO = 0'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'RETREAT_TO_BETTER_TERRAIN_DISTANCE = .*'
# new_pattern = r'RETREAT_TO_BETTER_TERRAIN_DISTANCE = 0'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'RETREAT_IF_MISSING_STRENGTH = .*'
# new_pattern = r'RETREAT_IF_MISSING_STRENGTH = 0.1'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# seduce and court
#file_path = game_path + r"/game/common/schemes/scheme_types/court_scheme.txt"
#with open(file_path, 'r', encoding='utf-8') as file:
#    content = file.read()
#regular_pattern = 'base_progress_goal =.*'
#new_pattern = 'base_progress_goal = 10'
#content = re.sub(regular_pattern, new_pattern, content)
#with open(file_path, 'w', encoding='utf-8') as file:
#    file.write(content)
#regular_pattern = 'minimum_success =.*'
#new_pattern = 'minimum_success = 100'
#content = re.sub(regular_pattern, new_pattern, content)
#with open(file_path, 'w', encoding='utf-8') as file:
#    file.write(content)
#
#file_path = game_path + r"/game/common/schemes/scheme_types/seduce_scheme.txt"
#with open(file_path, 'r', encoding='utf-8') as file:
#    content = file.read()
#regular_pattern = 'base_progress_goal =.*'
#new_pattern = 'base_progress_goal = 10'
#content = re.sub(regular_pattern, new_pattern, content)
#with open(file_path, 'w', encoding='utf-8') as file:
#    file.write(content)
#regular_pattern = 'minimum_success =.*'
#new_pattern = 'minimum_success = 100'
#content = re.sub(regular_pattern, new_pattern, content)
#with open(file_path, 'w', encoding='utf-8') as file:
#    file.write(content)

## buy claims
# file_path = game_path + r"/game/common/character_interactions/00_perk_interactions.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'target_is_liege_or_above = scope:actor'
# new_pattern = r'#target_is_liege_or_above = scope:actor'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'has_perk = sanctioned_loopholes_perk'
# new_pattern = r'is_close_or_extended_family_of = root'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# sale of titles
# file_path = game_path + r"/game/common/decisions/00_lifestyle_decisions.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'has_perk = at_any_cost_perk'
# new_pattern = r'is_close_or_extended_family_of = root'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'has_perk = it_is_my_domain_perk'
# new_pattern = r'is_close_or_extended_family_of = root'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

## claim throne
# file_path = game_path + r"/game/common/schemes/scheme_types/claim_throne_scheme.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'has_perk = meritocracy_perk'
# new_pattern = r'always = yes'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'is_landed = yes'
# new_pattern = r'#is_landed = yes'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# file_path = game_path + r"/game/common/character_interactions/00_perk_interactions.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'has_perk = meritocracy_perk'
# new_pattern = r'always = yes'
# content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'NOT = { government_allows = merit }'
# new_pattern = r'always = yes'
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

## murder
file_path = game_path + r"/game/common/schemes/scheme_types/murder_scheme.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'cooldown = { years = 10 }'
new_pattern = r'cooldown = { years = 0 }'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'modifier = murder_personal_grudge_opinion'
new_pattern = r'#modifier = murder_personal_grudge_opinion'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = 'base_progress_goal = .*'
new_pattern = r'base_progress_goal = 10'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## war
file_path = game_path + r"/game/common/character_interactions/00_war.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'has_raised_armies'
new_pattern = r'#has_raised_armies'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## war score
folder_path = game_path + r"/game/common/casus_belli_types"
for filename in os.listdir(folder_path):
    file_path = os.path.join(folder_path, filename)
    if os.path.isfile(file_path):  # 确保是文件而非文件夹
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()
        regular_pattern = 'max_attacker_score_from_battles =.*'
        new_pattern = 'max_attacker_score_from_battles = 1000'
        content = re.sub(regular_pattern, new_pattern, content)
        regular_pattern = 'max_defender_score_from_battles =.*'
        new_pattern = 'max_defender_score_from_battles = 1000'
        content = re.sub(regular_pattern, new_pattern, content)
        regular_pattern = 'add_truce_attacker_victory_effect = yes'
        new_pattern = '#add_truce_attacker_victory_effect = yes'
        content = re.sub(regular_pattern, new_pattern, content)
        regular_pattern = 'add_truce_attacker_defeat_effect = yes'
        new_pattern = '#add_truce_attacker_defeat_effect = yes'
        content = re.sub(regular_pattern, new_pattern, content)
        regular_pattern = 'add_truce_white_peace_effect = yes'
        new_pattern = '#add_truce_white_peace_effect = yes'
        content = re.sub(regular_pattern, new_pattern, content)
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(content)

# recruit courtier without money
file_path = game_path + r"/game/common/character_interactions/00_courtier_and_guest_interactions.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'gold >= scope:recipient.recruit_guest_interaction_cost'
new_pattern = r'#gold >= scope:recipient.recruit_guest_interaction_cost'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'gold = scope:most_expensive_person.recruit_guest_interaction_cost_with_list'
new_pattern = r'#gold = sacope:most_expensive_person.recruit_guest_interaction_cost_with_list'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'base = -50'
new_pattern = r'base = 9999'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# China!
file_path = game_path + r"/game/common/decisions/dlc_decisions/tgp/tgp_dynastic_cycle_decisions.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'percent >= claim_mandate_china_county_percentage_value'
new_pattern = r'percent >= 0.3'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

file_path = game_path + r"/game/common/situation/situations/tgp_dynastic_cycle.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'catalyst_hegemony_too_few_lands = extreme_situation_catalyst_over_time_gain'
new_pattern = r'#catalyst_hegemony_too_few_lands = extreme_situation_catalyst_over_time_gain'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'catalyst_hegemony_far_too_few_lands = @lost_mandate_of_heaven'
new_pattern = r'#catalyst_hegemony_far_too_few_lands = @lost_mandate_of_heaven'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'dynastic_cycle_offensive_wars_ban = yes'
new_pattern = r'#dynastic_cycle_offensive_wars_ban = yes'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'icon = "gfx/interface/icons/situation_types/dynastic_cycle.dds"'
new_pattern = r'''icon = "gfx/interface/icons/situation_types/dynastic_cycle.dds"
			geographical_regions = { world_asia }'''
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'catalyst_hegemon_below_maa_limit_yearly = major_situation_catalyst_over_time_gain'
new_pattern = r'#catalyst_hegemon_below_maa_limit_yearly = major_situation_catalyst_over_time_gain'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

file_path = game_path + r"/game/common/great_projects/types/00_ministry_projects.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'great_project_base_contribution_cost'
new_pattern = r'0'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'great_project_base_starting_cost'
new_pattern = r'0'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'great_project_base_construction_time'
new_pattern = r'365'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

# file_path = game_path + r"/game/common/modifiers/00_basic_modifiers.txt"
# with open(file_path, 'r', encoding='utf-8') as file:
#     content = file.read()
# regular_pattern = r'monthly_treasury_from_liege_mult ='
# new_pattern = r'#monthly_treasury_from_liege_mult ='
# content = re.sub(regular_pattern, new_pattern, content)
# with open(file_path, 'w', encoding='utf-8') as file:
#     file.write(content)

# adventure
file_path = game_path + r"/game/common/governments/00_government_types.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'conditional_maa_refill = yes'
new_pattern = r'#conditional_maa_refill = yes'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

file_path = game_path + r"/game/common/casus_belli_types/07_ep3_wars.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'prestige_level >='
new_pattern = r'#prestige_level >='
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## succession
file_path = game_path + r"/game/common/laws/00_succession_laws.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'can_keep_partition_succession_law_trigger = yes'
new_pattern = r'government_has_flag = government_is_feudal'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'can_change_partition_succession_law_trigger = yes'
new_pattern = r'government_has_flag = government_is_feudal'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'can_have_partition_succession_law_trigger = yes'
new_pattern = r'government_has_flag = government_is_feudal'
content = re.sub(regular_pattern, new_pattern, content)
# regular_pattern = r'order_of_succession = appointment'
# new_pattern = r'''order_of_succession = inheritance
# 			traversal_order = children
# 			rank = oldest
# 			title_division = partition'''
# content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## marry_off
file_path = game_path + r"/game/common/character_interactions/00_marriage_interactions.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'remove_from_list = characters'
new_pattern = r'#remove_from_list = characters'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'has_government = landless_adventurer_government'
new_pattern = r'always = no'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## laws
file_path = game_path + r"/game/common/laws/02_admininistrative_laws.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'border_war_sized_realm_value'
new_pattern = r'10 #border_war_sized_realm_value'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## religious head
file_path = game_path + r"/game/common/scripted_triggers/00_religious_triggers.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'COUNT ='
new_pattern = r'#COUNT ='
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)

## treasury
file_path = game_path + r"/game/common/character_interactions/10_tgp_interactions.txt"
with open(file_path, 'r', encoding='utf-8') as file:
    content = file.read()
regular_pattern = r'cooldown = { years = 2 }'
new_pattern = r'cooldown = { years = 1 }'
content = re.sub(regular_pattern, new_pattern, content)
regular_pattern = r'cooldown_against_recipient = { years = 10 }'
new_pattern = r'cooldown_against_recipient = { years = 1 }'
content = re.sub(regular_pattern, new_pattern, content)
with open(file_path, 'w', encoding='utf-8') as file:
    file.write(content)